package com.cn.xly2023.service.impl;

import com.cn.xly2023.mapper.GoodTypeMapper;
import com.cn.xly2023.pojo.Good;
import com.cn.xly2023.pojo.GoodType;
import com.cn.xly2023.pojo.PageBean;
import com.cn.xly2023.service.GoodTypeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class GoodTypeServiceImpl implements GoodTypeService {
    @Resource
    private GoodTypeMapper goodTypeMapper;

    @Transactional
    public PageBean selectAll(Integer page, Integer pageSize,
                              String typeName,Integer status,Integer ptypeId) {
        //1.使用pageHelper插件设置分页参数
        PageHelper.startPage(page, pageSize);
        //2.查询所有的信息
        List<GoodType> list = goodTypeMapper.select_all(typeName,status,ptypeId);
        PageInfo<GoodType> p = new PageInfo<>(list);
        //3.封装PageBean对象
        PageBean pageBean = new PageBean(p.getTotal(), p.getList());
        return pageBean;
    }

    public List<GoodType> selectByType(String typeName) {
        return goodTypeMapper.selectByType(typeName);
    }

    public void deleteById(Integer typeId) {
        goodTypeMapper.deleteById(typeId);
    }

    @Override
    public List<GoodType> insert(GoodType goodType) {
        return goodTypeMapper.insert(goodType);
    }

    public List<GoodType> selectByStatus(Integer status) {
        return goodTypeMapper.selectByStatus(status);
    }

    @Override
    public List<GoodType> updateByTypeName( GoodType goodType) {
        return goodTypeMapper.updateByTypeName(goodType);
    }

    @Override
    public List<GoodType> getAllPType() {
        List<GoodType> goodTypes = goodTypeMapper.getAllPType();
        return goodTypes;
    }

}
